#include "tri2d.h"

using namespace ePhys;

tri2d::tri2d(void)
{
	p1 = p2 = p3 = vec2d();
}

tri2d::tri2d(vec2d _p1, vec2d _p2, vec2d _p3)
{
	p1 = _p1;
	p2 = _p2;
	p3 = _p3;
}

tri2d::tri2d(tri2d *o)
{
	p1 = o->p1;
	p2 = o->p2;
	p3 = o->p3;
}


tri2d::~tri2d(void)
{
}

bool tri2d::inTriangle(vec2d pt) {
	float AB = (pt.y-p1.y)*(p2.x-p1.x) - (pt.x-p1.x)*(p2.y-p1.y);
	float CA = (pt.y-p3.y)*(p1.x-p3.x) - (pt.x-p3.x)*(p1.y-p3.y);
	float BC = (pt.y-p2.y)*(p3.x-p2.x) - (pt.x-p2.x)*(p3.y-p2.y);

	if (AB*BC>0.f && BC*CA>0.f)
		return true;
	return false;	 
}